package com.shelpe.services.suanzi.filters;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

public class TokenFilter extends ZuulFilter {

	@Value("${suanzi.token}")
	private String accessToken;
	
	@Override
	public Object run() {
		RequestContext ctx = RequestContext.getCurrentContext();
		Map<String, List<String>> params = ctx.getRequestQueryParams();
		
		List<String> values = new ArrayList<String>();
		values.add(accessToken);
		params.put("access_token", values);
		return null;
	}

	@Override
	public boolean shouldFilter() {
		return true;
	}

	@Override
	public int filterOrder() {
		return 0;
	}

	@Override
	public String filterType() {
		return "route";
	}

}
